package com.g8.pethospitallearnbackend.mapper;

import com.g8.pethospitallearnbackend.entity.Type;
import com.g8.pethospitallearnbackend.entity.TypeExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface TypeMapper {
    @SelectProvider(type=TypeSqlProvider.class, method="countByExample")
    long countByExample(TypeExample example);

    @DeleteProvider(type=TypeSqlProvider.class, method="deleteByExample")
    int deleteByExample(TypeExample example);

    @Delete({
        "delete from type",
        "where type_id = #{typeId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String typeId);

    @Insert({
        "insert into type (type_id, type_name)",
        "values (#{typeId,jdbcType=VARCHAR}, #{typeName,jdbcType=VARCHAR})"
    })
    int insert(Type record);

    @InsertProvider(type=TypeSqlProvider.class, method="insertSelective")
    int insertSelective(Type record);

    @SelectProvider(type=TypeSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="type_id", property="typeId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="type_name", property="typeName", jdbcType=JdbcType.VARCHAR)
    })
    List<Type> selectByExample(TypeExample example);

    @Select({
        "select",
        "type_id, type_name",
        "from type",
        "where type_id = #{typeId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="type_id", property="typeId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="type_name", property="typeName", jdbcType=JdbcType.VARCHAR)
    })
    Type selectByPrimaryKey(String typeId);

    @UpdateProvider(type=TypeSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Type record, @Param("example") TypeExample example);

    @UpdateProvider(type=TypeSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Type record, @Param("example") TypeExample example);

    @UpdateProvider(type=TypeSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Type record);

    @Update({
        "update type",
        "set type_name = #{typeName,jdbcType=VARCHAR}",
        "where type_id = #{typeId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Type record);

    //查询所有type数据
    @Select("select * from type")
    List<Type> selectAllTypes();

    @Select("select type_id from type where type_name=#{typeName};")
    String selectTypeIdByName(@Param("typeName") String typeName);

    @Select("select * from type where type_id=#{typeId};")
    Type selectAType(@Param("typeId") String typeId );

    @Select("select type_name from type where type_id=#{typeId};")
    String selectTypeNameById(@Param("typeId") String typeId);
}